package com.karaku.karaku_collector.keepalive;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.karaku.karaku_collector.activity.MainActivity;
import com.karaku.karaku_collector.common.KarakuActivityManager;
import com.karaku.karaku_collector.util.LogUtil;

public class KeepAliveReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        LogUtil.d("KEEP_ALIVE", "onReceive0");
        if (!KarakuActivityManager.hasActivity(MainActivity.class) || !KarakuActivityManager.appIsFront()) {
            LogUtil.d("KEEP_ALIVE", "onReceive1");
            Intent i = new Intent(Intent.ACTION_MAIN);
            i.addCategory(Intent.CATEGORY_LAUNCHER);
            i.setClass(context, MainActivity.class);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            context.startActivity(i);
        }
    }
}
